home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / Tool Chest / QuickDraw / Animation / SpriteMgr.h < prev   
Encoding:
Text File  |  1992-09-01  |  7.4 KB  |  237 lines  |  [TEXT/MPS ]

  1. /*
  2.  
  3.  
  4.     © Copyright 1991 Ricardo Batista,  All Rights Reserved.
  5.     
  6.     
  7.     Prototypes for the Color Sprite Manager
  8.     
  9.     
  10.     04/20/91
  11.     
  12.     
  13.     HISTORY:  (Most Recent first)
  14.     
  15.     
  16.     04/23/91    rb    Finished first functional spec and prototypes.
  17.     04/20/91    rb    New today
  18.     
  19.     
  20.     SOME ELEMENTS FROM THIS FILE WILL BE MOVED INTO A PRIVATE INTERFACE.
  21.     
  22. */
  23.  
  24.  
  25.  
  26. // #include <Types.h>
  27. // #include <QuickDraw.h>
  28. // #include <QDOffscreen.h>
  29.  
  30.  
  31.  
  32.  
  33. typedef struct {
  34.     QElemPtr qLink;
  35.     short qType;
  36.     ProcPtr vblAddr;
  37.     short vblCount;
  38.     short vblPhase;
  39.     short inVBL;
  40. } taskRecord;
  41.  
  42.  
  43. #define        kMaxUR            20
  44.  
  45.  
  46.  
  47. typedef struct {
  48.  
  49.         Ptr                    nextSprite;            // pointer to next SpriteInfoRec
  50.         short                id;                    // sprite unique id
  51.         short                drawOrder;            // drawing order, 1 being first
  52.         short                copyMode;            // usually transparent, srcCopy or blend
  53.         short                pictID;                // the PICT id where this sprite was copied from
  54.         short                currentFace;        // current face we are displaying 1 based
  55.         short                faces;                // total number of faces for this sprite
  56.         Rect                animationRect;        // location of sprite in animation screen or 0's
  57.         Rect                collisionRect;        // animation origin collison rectangle
  58.         Rect                spriteRect;            // rectangle wich encloses the sprite (local coord)
  59.         Rect                oldAnimationRect;    // area that needs to be updated in animation
  60.         GWorldPtr            spriteWorld;        // graphics world which contains sprite and faces
  61.         unsigned long        tickWait;            // tick count before calling tickProc or changing face
  62.         unsigned long        lastTick;            // last time we tickled this sprite
  63.         ProcPtr                tickProc;            // proc to call on ticks or nil for auto face change
  64.         ProcPtr                collisionProc;        // proc to call on collisions or nil
  65.         Boolean                sharedWorld;        // true if this gworld is actually shared with others
  66.         Boolean                changed;            // true if the face of the sprite has changed, needs update
  67.         Boolean                canCollide;            // used to enable/disable collisions
  68.         Boolean                hidden;                // used to show/hide the sprite
  69.         Ptr                    userPtr;            // for app owned extra information
  70.         Ptr                    reserved;            // who knows what the future might bring
  71.         
  72. } SpriteInfoRec, *SpriteInfoRecPtr;
  73.  
  74.  
  75.  
  76. typedef struct {
  77.  
  78.         Ptr                    nextScenery;        // pointer to next SceneryInfoRec
  79.         short                id;                    // unique id number of this scenery
  80.         short                pictID;                // PICT resource where scenery was copied from
  81.         short                drawOrder;            // order in which sceneries are drawn 1 = first
  82.         short                copyMode;            // srcCopy for 1'st back, transparent for most
  83.         GWorldPtr            sceneryWorld;        // graphics world which contains scenery
  84.         Rect                animationRect;        // rect in animation world occupied by this scenery
  85.         Rect                sceneryRect;        // gworld based rectangle ready for copybits
  86.         Point                scrollOffset;        // offset used for scrolling scenery
  87.         Point                autoScrollAmount;    // for the autoscrolling
  88.         long                scrollTicks;        // tick count for automatic scrolling if not zero
  89.         long                nextTickCount;        // when this tick arrives is time to autoscroll
  90.         Boolean                hidden;                // so we can "hide" backgrounds
  91.         Boolean                changed;            // marks that needs to be updated in animation
  92.         Boolean                shared;                // are we sharing gWorlds ?
  93.         
  94. } SceneryInfoRec, *SceneryInfoRecPtr;
  95.  
  96.  
  97.  
  98. typedef struct {
  99.  
  100.     SpriteInfoRecPtr        backSprites;        // linked list of background sprites
  101.     SpriteInfoRecPtr        normSprites;        // linked list of sprites
  102.     SpriteInfoRecPtr        foreSprites;        // linked list of foreground sprites
  103.     SceneryInfoRecPtr        backgrounds;        // linked list of backgrounds;
  104.     SceneryInfoRecPtr        foregrounds;        // linked list of foregrounds;
  105.     CWindowPtr                animationWindow;    // our window, where animation goes
  106.     GWorldPtr                animationGWorld;    // graphics world for end animation
  107.     Rect                    animationRect;        // rectangle of animation window which belongs to us
  108.     CTabHandle                originalCTable;        // the original color table, must be restored later
  109.     CTabHandle                currCTable;            // the current color table
  110.     short                    originalDepth;        // original pixel depth of device, to be restored
  111.     taskRecord                task;                // vbl task for smooth animation
  112.     GDHandle                deviceUsed;            // the graphics device of preference
  113.     Boolean                    active;                // is our animation active ?
  114.     Boolean                    redoCheck;            // redo update check if nessesary
  115.     Boolean                    changed;            // true if animation has changed
  116.     Rect                    changedRect[kMaxUR];    // update rectangles (for speed)
  117.     short                    updateRects;        // how many are in use ?
  118.  
  119. } SpriteMgrRec, *SpriteMgrRecPtr;
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127. short InitSpriteMgr(CTabHandle cTable);
  128.     
  129. void CloseSpriteMgr(void);
  130.  
  131. short NewBackground(short pictID, short drawOrder, short copyMode, Rect *animationRect,
  132.                     short id);
  133.  
  134. short NewForeground(short pictID, short drawOrder, short copyMode, Rect *animationRect,
  135.                     short id);
  136.  
  137. void ScrollBackground(short id, short vOffset, short hOffset);
  138.  
  139. void ScrollForeground(short id, short vOffset, short hOffset);
  140.  
  141. void AutoScrollBackground(short id, short vOffset, short hOffset, long scrollTicks);
  142.  
  143. void AutoScrollForeground(short id, short vOffset, short hOffset, long scrollTicks);
  144.  
  145. void KillBackground(short id);
  146.  
  147. void KillForeground(short id);
  148.  
  149. short NewBackgroundSprite(short pictID, short totalPicts, short copyMode,
  150.                         ProcPtr spriteProc, long ProcTicks, short drawOrder,
  151.                         ProcPtr collisionProc, Boolean canColide, short id);
  152.  
  153. short NewSprite(short pictID, short totalPicts, short copyMode,
  154.                         ProcPtr spriteProc, long ProcTicks, short drawOrder,
  155.                         ProcPtr collisionProc, Boolean canColide, short id);
  156.  
  157. short NewForegroundSprite(short pictID, short totalPicts, short copyMode,
  158.                         ProcPtr spriteProc, long ProcTicks, short drawOrder,
  159.                         ProcPtr collisionProc, Boolean canColide, short id);
  160.  
  161. CWindowPtr NewAnimation(Rect *animationRect, short windowH, short windowV, Str255 wTitle);
  162.  
  163. void SetCurrentSpriteIndex(short id, short index);
  164.     
  165. void PutSprite(short id, short top, short left);
  166.  
  167. void RemoveSprite(short id);
  168.     
  169. void MoveSprite(short id, short h, short v, short newIndex);
  170.  
  171. void MoveSpriteTo(short id, short h, short v, short newIndex);
  172.     
  173. void ShowSprite(short id, Boolean show);
  174.     
  175. void GetSpriteLocation(short id, Rect *location);
  176.  
  177. void EnableSpriteCollisions(short id, Boolean enable);    
  178.     
  179. void ValidateOldSpriteLocation(short id);
  180.     
  181. void SetSpriteCollisionRect(short id, Rect *colRect);
  182.     
  183. SpriteInfoRecPtr GetSpriteInfo(short id);
  184.     
  185. void KillSprite(short id);
  186.     
  187. void ActivateAnimation(void);
  188.     
  189. void DeactivateAnimation(void);
  190.  
  191. void DoAnimation(Boolean update);
  192.  
  193. void SetNewAnimationPallete(CTabHandle cTable);
  194.  
  195.  
  196. /*******************************************************************************************
  197.  
  198.     P R I V A T E      R O U T I N E S
  199.     
  200.     
  201. *******************************************************************************************/
  202.  
  203.  
  204.  
  205.  
  206. extern void VTASK(void);
  207.  
  208. short NewScenery(short pictID, short drawOrder, short copyMode, Rect *animationRect,
  209.                 short id, Boolean back);
  210.  
  211. short SMgrNewSprite(short pictID, short totalPicts, short copyMode,
  212.                         ProcPtr spriteProc, long ProcTicks, short drawOrder,
  213.                         ProcPtr collisionProc, Boolean canCollide, short id, short sType);
  214.  
  215. SpriteInfoRecPtr FindSprite(short id);
  216.  
  217. SpriteInfoRecPtr FindTwinSprite(short pictID);
  218.  
  219. SceneryInfoRecPtr FindTwinScenery(short pictID);
  220.  
  221. void CheckChangedScenery(SceneryInfoRecPtr scenery);
  222.  
  223. void CheckChangedSprite(SpriteInfoRecPtr sprite);
  224.  
  225. void UpdateScenery(SceneryInfoRecPtr scenery);
  226.  
  227. void UpdateSprite(SpriteInfoRecPtr sprite);
  228.  
  229. void MarkSceneryInRect(Rect *box, SceneryInfoRecPtr scenery);
  230.  
  231. void MarkSpriteInRect(Rect *box, SpriteInfoRecPtr sprite);
  232.  
  233. void CopyGToScreen(void);
  234.  
  235. Boolean SMgrPtInRect(Point pixel, Rect *box);
  236.  
  237. Boolean RectIntersect(Rect *r, Rect *box);